﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using wh40klbModel;

namespace wathammer40kListBuilder.ViewModel
{
    class ArmyViewModel : ViewModel
    {
        //Member
        private Army army;
        private List<SquadTypeViewModel> squadTypes;



        public ArmyViewModel()
        {

            try
            {
                using (WarhammerContext context = new WarhammerContext())
                {
                    SquadTypes = context.SquadTypes.Select(st => new SquadTypeViewModel { SquadType = st }).ToList();
                }
                army = new Army();
            }
            catch (Exception)
            {

            }
        }


        public bool SaveArmy()
        {
            using (WarhammerContext context = new WarhammerContext())
            {
                context.Armies.Add(army);
                context.SaveChanges();
            }
            return false;
        }
        //Properties
        public string Name
        {
            get { return army.Name; }
            set
            {
                army.Name = value;
                this.onPropertyChanged("Name");
            }
        }
        public List<SquadTypeViewModel> SquadTypes
        {
            get { return squadTypes; }
            set
            {
                squadTypes = value;
                this.onPropertyChanged("SquadTypes");
            }
        }
    }
}
